<template>
  <div class="divBox">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div class="container">
          <el-form inline>
            <el-form-item label="资产编号：">
              <el-input v-model="tableFrom.name" placeholder="请输入" class="selWidth" clearable />
            </el-form-item>
            <el-form-item label="启动状态" prop="roleKey">
              <el-select
                v-model="tableFrom.status"
                placeholder="角色状态"
                clearable
                style="width: 240px"
              >
                <el-option
                  v-for="dict in dict.type.sys_normal_disable"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="起始时间" prop="roleKey">
              <el-date-picker
                v-model="tableFrom.dateRange"
                style="width: 240px"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              ></el-date-picker>
            </el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="getList(1)">搜索</el-button>
          </el-form>
        </div>
        <el-button size="mini" type="primary" @click="add">新增</el-button>
      </div>
      <el-table
        v-loading="listLoading"
        :data="tableData.data"
        size="mini"
        ref="multipleTable"
        :header-cell-style=" {fontWeight:'bold'}"
      >
        <!-- <el-table-column label="序号"  type="index" /> -->
        <!-- <el-table-column prop="sort" label="排序"/> -->
        <el-table-column prop="homeName" label="表号" />
        <el-table-column prop="homeAddress" label="当前读数" />
        <el-table-column prop="homeIntegral" label="倍率" />
        <el-table-column prop="homeInfo" label="是否启用" />
        <el-table-column prop="homeInfo" label="起始读数" />
        <el-table-column prop="homeInfo" label="租赁合同号" />
        <el-table-column prop="homeInfo" label="租赁客户" />
        <el-table-column prop="homeInfo" label="是否分配" />
        <el-table-column prop="homeInfo" label="最新读表时间" />
        <el-table-column prop="homeInfo" label="物业合同" />
        <el-table-column prop="homeInfo" label="所属环境" />

        <el-table-column label="操作" min-width="200" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="handleEdit(scope.row)">编辑</el-button>
            <el-button type="text" size="small" @click="handleDelete(scope.row, scope.$index)">删除</el-button>
            <!-- <el-button
              type="text"
              size="small"
              @click="handleView(scope.row.id, scope.$index)"
              class="mr10"
            >家庭成员</el-button>-->
          </template>
        </el-table-column>
      </el-table>
      <div class="block mb20">
        <el-pagination
          :page-sizes="[10, 20, 30, 40]"
          :page-size="tableFrom.limit"
          :current-page="tableFrom.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.total"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </div>
    </el-card>

    <el-dialog
      :title="isCreate===0 ? '添加数据' : '编辑数据'"
      :visible.sync="dialogVisible"
      width="1200px"
      :before-close="handleClose"
      v-if="dialogVisible"
    >
      <div v-loading="loading">
        <restaurantDialog
          ref="restaurantDialog"
          :isCreate="isCreate"
          :categoryOptions="categoryOptions"
          :selectItem="selectItem"
          @getList="getList(1)"
          @close="handleClose"
        ></restaurantDialog>
      </div>
    </el-dialog>
  </div>
</template>
  
  <script>
import {
  listRole,
  getRole,
  delRole,
  addRole,
  updateRole,
  dataScope,
  changeRoleStatus,
  deptTreeSelect
} from "@/api/system/role";
import restaurantDialog from "./restaurantDialog";
import { homeGetList, homeGetDelete } from "@/api/village";
export default {
  dicts: ["sys_normal_disable"],
  name: "advertisingSpaceManage",
  components: { restaurantDialog },
  data() {
    return {
      time: undefined,
      dialogVisible: false,
      isCreate: 0,
      selectItem: undefined,
      listLoading: true,
      tableData: {
        data: [],
        total: 0
      },
      tableFrom: {
        page: 1,
        limit: 20,
        name: undefined, //名称
        isShow: undefined //抢购状态
      },
      loading: false,
      categoryOptions: []
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    // 删除
    handleDelete(row, idx) {
      const roleIds = row.roleId || this.ids;
      this.$modal
        .confirm("确定要删除吗？")
        .then(function() {
          return delRole(roleIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
      return;
      // let data={
      //   id:id
      // }
      this.$modalSure().then(() => {
        homeGetDelete({ id: id }).then(() => {
          this.$message.success("删除成功");
          this.tableData.data.splice(idx, 1);
        });
      });
    },

    // 编辑
    handleEdit(row) {
      this.selectItem = row;
      this.isCreate = 1;
      this.dialogVisible = true;
    },

    // 列表
    getList(num) {
      this.listLoading = true;
      this.tableFrom.page = num ? num : this.tableFrom.page;
      listRole(this.tableFrom)
        .then(res => {
          console.log(res, "dd");
          this.tableData.data = res.rows;
          this.tableData.total = res.total;
          this.tableData.data.map(item => this.$set(item, "isEdit", false));
          this.listLoading = false;
        })
        .catch(res => {
          this.listLoading = false;
        });
    },
    pageChange(page) {
      this.tableFrom.page = page;
      this.getList();
    },
    handleSizeChange(val) {
      this.tableFrom.limit = val;
      this.getList();
    },
    handleStatusChange(id, name) {
      if (name === "上架") {
        postCateringStatus({ ids: id, isShow: 1 }).then(() => {
          this.getList(1);
        });
      }

      if (name === "下架") {
        postCateringStatus({ ids: id, isShow: 0 }).then(() => {
          this.getList(1);
        });
      }
    },
    add() {
      this.selectItem = undefined;
      this.isCreate = 0;
      this.dialogVisible = true;
    },
    handleClose() {
      this.dialogVisible = false;
    },

    //跳转套餐
    handleView(id) {
      this.$router.push(`/family/restaurantManage2?id=${id}`);
    }
  }
};
</script>
  
  <style scoped>
</style>
  